<?php
class Mod_gopy extends CI_Controller{
    private $setting;
    function  __construct(){
        parent::__construct();
        $this->setting =$this->common_model->getone('setting',array('id'=>1));
        $this->load->helper(array('form', 'text','chuyendoitv_helper'));
        $this->load->library('form_validation');
    }
    function index(){
        $data['gopy'] = $this->common_model->getone('gopy',array('publish'=>1),array('ten','id','tieude','noidung'));
        $this->load->view('mod_gopy/gopy',$data);
	}
    function danhsach(){
        if($_POST){
            $this->form_validation->set_rules('ten','Tên','required');
            $this->form_validation->set_rules('email','Email','required|vali_email');
            $this->form_validation->set_rules('dienthoai','Điện thoại','required|numeric|max_length[12]|min_length[9]');
            $this->form_validation->set_rules('tieude','Tiêu đề','required');
            $this->form_validation->set_rules('noidung','Nội dung','required');
            $this->form_validation->set_error_delimiters('| <span class="loi">', '</span>');
            if($this->form_validation->run() == FALSE){
                    
            }else{
                $data= $this->security->xss_clean($_POST);
                $data['ip']=$this->input->ip_address();
                $this->db->insert('gopy', $data); 
                $this->session->set_userdata('gopy','Ý kiến của bạn đã được gửi,chúng tôi sẽ kiểm tra nội dung trước khi ý kiến của bạn được hiện trên trang web. Xin cảm ơn');
              
            }
            }
            
            $start_limit=$this->uri->segment(3);
            $this->base_url_trang = base_url().'gopy/danhsach/';
            $this->total_rows =$this->common_model->getnumber('gopy');
            $this->per_page =10;
            $this->uri_phantrang =3;
            $this->phantrang();
            $data1 =array('data2'=>$this->common_model->getdata('gopy',array('publish'=>1),'',array('id','DESC'),array($this->per_page,$start_limit)));
            $data['content']=$this->load->view('mod_gopy/list',$data1,true);
            $data['title'] = $this->setting->title;
            $data['metades'] = $this->setting->metades;
            $data['metakey'] = $this->setting->metakey;                        
            $this->load->view('default/index',$data); 
            
    }
    function nd_gopy(){
        
        if($this->uri->segment(3,0)=='show'){
            $id=$this->uri->segment(4);            
            $data['dulieu']=$this->common_model->getone('gopy',array('id'=>$id));
            if(!empty($data)){
                $this->load->view('mod_gopy/ndgopy',$data);
            }else echo 'Nội dung không tồn tại hoặc đã bị xóa!';
            
        }        
    }
    function phantrang(){
        //$data =array('data'=>$this->Admin_model->get_data($table,$where,$order,$limit,$start_limit),
        $this->load->library('pagination');
        $config['base_url'] = $this->base_url_trang;
        $config['total_rows'] = $this->total_rows;
        $config['per_page'] = $this->per_page;
        $config['uri_segment'] = $this->uri_phantrang;
        $config['num_links'] = 12;
        $config['first_link'] = '<<';
        $config['first_tag_open'] = '<li class="firt_pag">';//div cho chu <<
        $config['first_tag_close'] = '</li>';//div cho chu <<
        $config['last_link'] = '>>';
        $config['last_tag_open'] = '<li class="last_pag">';
        $config['last_tag_close'] = '</li>';
        //-------next-
        $config['next_link'] = 'next &gt;';
        $config['next_tag_open'] = '<li>';
        $config['next_tag_close'] = '</li>';
        //------------preview
        $config['prev_link'] = '&lt; prev';
        $config['prev_tag_open'] = '<li>';
        $config['prev_tag_close'] = '</li>';
       // ------------------cu?npage
        $config['cur_tag_open'] = '<li class="current">';
        $config['cur_tag_close'] = '</li>';
        //--so 
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';
        //-----
        $this->pagination->initialize($config);
    
    }
    
}